<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="id" prop="id">
        <el-input
          v-model="queryParams.id"
          placeholder="请输入id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="场站id" prop="changzhanid">
        <el-input
          v-model="queryParams.changzhanid"
          placeholder="请输入场站id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="编号" prop="bianhao">
        <el-input
          v-model="queryParams.bianhao"
          placeholder="请输入编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="型号id" prop="xinghaoid">
        <el-input
          v-model="queryParams.xinghaoid"
          placeholder="请输入型号id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['ruoyi-yuce:nibianqi:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['ruoyi-yuce:nibianqi:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['ruoyi-yuce:nibianqi:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['ruoyi-yuce:nibianqi:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="nibianqiList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="场站id" align="center" prop="changzhanid" />
      <el-table-column label="电压等级" align="center" prop="dianyadengjiid" />
      <el-table-column label="编号" align="center" prop="bianhao" />
      <el-table-column label="名字" align="center" prop="mingzi" />
      <el-table-column label="机电箱id" align="center" prop="jidianxianid" />
      <el-table-column label="厂家id" align="center" prop="changjiaid" />
      <el-table-column label="型号id" align="center" prop="xinghaoid" />
      <el-table-column label="序列号" align="center" prop="xuliehao" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['ruoyi-yuce:nibianqi:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['ruoyi-yuce:nibianqi:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改逆变器对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="场站id" prop="changzhanid">
          <el-input v-model="form.changzhanid" placeholder="请输入场站id" />
        </el-form-item>
        <el-form-item label="电压等级" prop="dianyadengjiid">
          <el-input v-model="form.dianyadengjiid" placeholder="请输入电压等级" />
        </el-form-item>
        <el-form-item label="编号" prop="bianhao">
          <el-input v-model="form.bianhao" placeholder="请输入编号" />
        </el-form-item>
        <el-form-item label="名字" prop="mingzi">
          <el-input v-model="form.mingzi" placeholder="请输入名字" />
        </el-form-item>
        <el-form-item label="fenqi" prop="fenqi">
          <el-input v-model="form.fenqi" placeholder="请输入fenqi" />
        </el-form-item>
        <el-form-item label="机电箱id" prop="jidianxianid">
          <el-input v-model="form.jidianxianid" placeholder="请输入机电箱id" />
        </el-form-item>
        <el-form-item label="fangzhen" prop="fangzhen">
          <el-input v-model="form.fangzhen" placeholder="请输入fangzhen" />
        </el-form-item>
        <el-form-item label="厂家id" prop="changjiaid">
          <el-input v-model="form.changjiaid" placeholder="请输入厂家id" />
        </el-form-item>
        <el-form-item label="型号id" prop="xinghaoid">
          <el-input v-model="form.xinghaoid" placeholder="请输入型号id" />
        </el-form-item>
        <el-form-item label="序列号" prop="xuliehao">
          <el-input v-model="form.xuliehao" placeholder="请输入序列号" />
        </el-form-item>
        <el-form-item label="MinMMPV" prop="minmmpv">
          <el-input v-model="form.minmmpv" placeholder="请输入MinMMPV" />
        </el-form-item>
        <el-form-item label="MaxMMPV" prop="maxmmpv">
          <el-input v-model="form.maxmmpv" placeholder="请输入MaxMMPV" />
        </el-form-item>
        <el-form-item label="MaxInputV" prop="maxinputv">
          <el-input v-model="form.maxinputv" placeholder="请输入MaxInputV" />
        </el-form-item>
        <el-form-item label="MaxInputI" prop="maxinputi">
          <el-input v-model="form.maxinputi" placeholder="请输入MaxInputI" />
        </el-form-item>
        <el-form-item label="PVShortCircuitI" prop="pvshortcircuiti">
          <el-input v-model="form.pvshortcircuiti" placeholder="请输入PVShortCircuitI" />
        </el-form-item>
        <el-form-item label="RatedOutputP" prop="ratedoutputp">
          <el-input v-model="form.ratedoutputp" placeholder="请输入RatedOutputP" />
        </el-form-item>
        <el-form-item label="RatedOutputI" prop="ratedoutputi">
          <el-input v-model="form.ratedoutputi" placeholder="请输入RatedOutputI" />
        </el-form-item>
        <el-form-item label="RatedOutputf" prop="ratedoutputf">
          <el-input v-model="form.ratedoutputf" placeholder="请输入RatedOutputf" />
        </el-form-item>
        <el-form-item label="MaxOutputI" prop="maxoutputi">
          <el-input v-model="form.maxoutputi" placeholder="请输入MaxOutputI" />
        </el-form-item>
        <el-form-item label="Capacity" prop="capacity">
          <el-input v-model="form.capacity" placeholder="请输入Capacity" />
        </el-form-item>
        <el-form-item label="createdate" prop="createdate">
          <el-date-picker clearable
            v-model="form.createdate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择createdate">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="creator" prop="creator">
          <el-input v-model="form.creator" placeholder="请输入creator" />
        </el-form-item>
        <el-form-item label="delflag" prop="delflag">
          <el-input v-model="form.delflag" placeholder="请输入delflag" />
        </el-form-item>
        <el-form-item label="updatedate" prop="updatedate">
          <el-date-picker clearable
            v-model="form.updatedate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择updatedate">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="updater" prop="updater">
          <el-input v-model="form.updater" placeholder="请输入updater" />
        </el-form-item>
        <el-form-item label="BRANCH1FLAG" prop="branch1flag">
          <el-input v-model="form.branch1flag" placeholder="请输入BRANCH1FLAG" />
        </el-form-item>
        <el-form-item label="BRANCH2FLAG" prop="branch2flag">
          <el-input v-model="form.branch2flag" placeholder="请输入BRANCH2FLAG" />
        </el-form-item>
        <el-form-item label="BRANCH3FLAG" prop="branch3flag">
          <el-input v-model="form.branch3flag" placeholder="请输入BRANCH3FLAG" />
        </el-form-item>
        <el-form-item label="BRANCH4FLAG" prop="branch4flag">
          <el-input v-model="form.branch4flag" placeholder="请输入BRANCH4FLAG" />
        </el-form-item>
        <el-form-item label="BRANCH5FLAG" prop="branch5flag">
          <el-input v-model="form.branch5flag" placeholder="请输入BRANCH5FLAG" />
        </el-form-item>
        <el-form-item label="BRANCH6FLAG" prop="branch6flag">
          <el-input v-model="form.branch6flag" placeholder="请输入BRANCH6FLAG" />
        </el-form-item>
        <el-form-item label="BRANCH7FLAG" prop="branch7flag">
          <el-input v-model="form.branch7flag" placeholder="请输入BRANCH7FLAG" />
        </el-form-item>
        <el-form-item label="BRANCH8FLAG" prop="branch8flag">
          <el-input v-model="form.branch8flag" placeholder="请输入BRANCH8FLAG" />
        </el-form-item>
        <el-form-item label="BRANCH9FLAG" prop="branch9flag">
          <el-input v-model="form.branch9flag" placeholder="请输入BRANCH9FLAG" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listNibianqi, getNibianqi, delNibianqi, addNibianqi, updateNibianqi } from "@/api/ruoyi-yuce/nibianqi";

export default {
  name: "Nibianqi",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 逆变器表格数据
      nibianqiList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: null,
        changzhanid: null,
        bianhao: null,
        xinghaoid: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [
          { required: true, message: "id不能为空", trigger: "blur" }
        ],
        changzhanid: [
          { required: true, message: "场站id不能为空", trigger: "blur" }
        ],
        dianyadengjiid: [
          { required: true, message: "电压等级不能为空", trigger: "blur" }
        ],
        bianhao: [
          { required: true, message: "编号不能为空", trigger: "blur" }
        ],
        mingzi: [
          { required: true, message: "名字不能为空", trigger: "blur" }
        ],
        fenqi: [
          { required: true, message: "fenqi不能为空", trigger: "blur" }
        ],
        jidianxianid: [
          { required: true, message: "机电箱id不能为空", trigger: "blur" }
        ],
        fangzhen: [
          { required: true, message: "fangzhen不能为空", trigger: "blur" }
        ],
        changjiaid: [
          { required: true, message: "厂家id不能为空", trigger: "blur" }
        ],
        xinghaoid: [
          { required: true, message: "型号id不能为空", trigger: "blur" }
        ],
        branch1flag: [
          { required: true, message: "BRANCH1FLAG不能为空", trigger: "blur" }
        ],
        branch2flag: [
          { required: true, message: "BRANCH2FLAG不能为空", trigger: "blur" }
        ],
        branch3flag: [
          { required: true, message: "BRANCH3FLAG不能为空", trigger: "blur" }
        ],
        branch4flag: [
          { required: true, message: "BRANCH4FLAG不能为空", trigger: "blur" }
        ],
        branch5flag: [
          { required: true, message: "BRANCH5FLAG不能为空", trigger: "blur" }
        ],
        branch6flag: [
          { required: true, message: "BRANCH6FLAG不能为空", trigger: "blur" }
        ],
        branch7flag: [
          { required: true, message: "BRANCH7FLAG不能为空", trigger: "blur" }
        ],
        branch8flag: [
          { required: true, message: "BRANCH8FLAG不能为空", trigger: "blur" }
        ],
        branch9flag: [
          { required: true, message: "BRANCH9FLAG不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询逆变器列表 */
    getList() {
      this.loading = true;
      listNibianqi(this.queryParams).then(response => {
        this.nibianqiList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        changzhanid: null,
        dianyadengjiid: null,
        bianhao: null,
        mingzi: null,
        fenqi: null,
        jidianxianid: null,
        fangzhen: null,
        changjiaid: null,
        xinghaoid: null,
        xuliehao: null,
        minmmpv: null,
        maxmmpv: null,
        maxinputv: null,
        maxinputi: null,
        pvshortcircuiti: null,
        ratedoutputp: null,
        ratedoutputi: null,
        ratedoutputf: null,
        maxoutputi: null,
        capacity: null,
        createdate: null,
        creator: null,
        delflag: null,
        updatedate: null,
        updater: null,
        branch1flag: null,
        branch2flag: null,
        branch3flag: null,
        branch4flag: null,
        branch5flag: null,
        branch6flag: null,
        branch7flag: null,
        branch8flag: null,
        branch9flag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加逆变器";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getNibianqi(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改逆变器";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateNibianqi(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addNibianqi(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除逆变器编号为"' + ids + '"的数据项？').then(function() {
        return delNibianqi(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('ruoyi-yuce/nibianqi/export', {
        ...this.queryParams
      }, `nibianqi_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
